package net.superdvach.core;
import java.util.Properties;
import java.io.*;

public class Config {

	public Config(String filename) {
		m_properties = new Properties();
		m_filename = filename;
	}

	public boolean load() {
		try {
			FileInputStream stream = new FileInputStream(new File(m_filename));
			m_properties.load(stream);
		} catch (FileNotFoundException e) {
			return false;
		} catch (IOException e) {
			return false;
		}
		return true;
	}

	public boolean save() {
		try {
			FileOutputStream stream = new FileOutputStream(new File(m_filename));
			m_properties.store(stream, "Superdvach config");
		} catch (FileNotFoundException e) {
			return false;
		} catch (IOException e) {
			return false;
		}
		return true;
	}

	public boolean delete() {
		return (new File(m_filename).delete());
	}

	public String getProperty(String key) {
		return m_properties.getProperty(key);
	}

	public String getProperty(String key, String defaultValue) {
		return m_properties.getProperty(key, defaultValue);
	}

	public void setProperty(String key, String value) {
		m_properties.setProperty(key, value);
	}

	private Properties m_properties;
	private String m_filename;
}
